
package xj.graph2d.app.diagram;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

import xj.graph2d.app.DrawAction;

public class BuildPackageDiagramTestListener 
  extends DrawAction 
  implements ActionListener {

  public void actionPerformed(ActionEvent e) {
    if (e != null) { 
      Object src =e.getSource();
      if (src instanceof JMenuItem) { 
	JMenuItem mi = (JMenuItem) src;
	String cmd = mi.getActionCommand(); 
	if ("Package1".equals(cmd)) { 
	  test1();
	} else if ("Package2".equals(cmd)) { 
	  test2(); 
	} else if ("Package3".equals(cmd)) { 
	  test3(); 
	}
      }
    }
  }

  private void test1() { 
    PackageDiagramBuilder builder = new PackageDiagramBuilder(main, "Package Diagram Test 1");
    builder.addPackage("pkg1", false); 
    builder.addPackage("pkg2", false); 
    builder.addPackage("pkg3", true); 
    builder.addPackage("pkg4", true); 
    builder.doLayout();
  }

  private void test2() { 
    PackageDiagramBuilder builder = new PackageDiagramBuilder(main, "Package Diagram Test 2");
    builder.addPackage("pkg1", false); 
    builder.addSubpackage("pkg1", "pkg2", false); 
    builder.addSubpackage("pkg1", "pkg3", true); 
    builder.addSubpackage("pkg1.pkg2", "xyz", true); 
    builder.addSubpackage("pkg1.pkg2", "abc", true); 

    builder.doLayout();
  }

  private void test3() { 
    PackageDiagramBuilder builder = new PackageDiagramBuilder(main, "Package Diagram Test 3");
    builder.addPackage("pkg1", true); 
    builder.addPackage("pkg2", true); 
    builder.addPackage("pkg3", true); 
    builder.addPackage("pkg4", true); 
    builder.addPackage("pkg5", true); 
    builder.addDependency("pkg1", "pkg2");
    builder.addDependency("pkg1", "pkg3");
    builder.addDependency("pkg1", "pkg4");
    builder.addDependency("pkg2", "pkg5");

    builder.addPackage("pkg100", false);

    builder.doLayout();
  }
}
